package com.nf.health.app.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.utils.DensityUtil;

/**
 * 公用dialog，布局请自定义添加
 * @author yuyahao
 */

public class ShowCommentDialog extends Dialog {
    private LinearLayout ll_contentshowdatal;
    private Context context;
    public ShowCommentDialog(Context context) {
        super(context,  R.style.Dialog_Fullscreen);
        this.context = context;
        ll_contentshowdatal = new LinearLayout(context);
        ll_contentshowdatal.setOrientation(LinearLayout.VERTICAL);
        setContentView(ll_contentshowdatal);

    }
    public ShowCommentDialog(Context context, int themeResId) {
        super(context,  R.style.Dialog_Fullscreen);
        this.context = context;
        ll_contentshowdatal = new LinearLayout(context);
        ll_contentshowdatal.setOrientation(LinearLayout.VERTICAL);
        setContentView(ll_contentshowdatal);
    }
    // 初始化弹出框
    public ShowCommentDialog showMyPersionDoctor(){
        ImageView imageView = new ImageView(context);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        imageView.setLayoutParams(params);
        imageView.setImageResource(R.drawable.data_dialog_image7);
        ll_contentshowdatal.setPadding(DensityUtil.dip2px(context,5),DensityUtil.dip2px(context,30),0, 0);
        ll_contentshowdatal.setGravity( Gravity.LEFT| Gravity.TOP);
        ll_contentshowdatal.addView(imageView);
        return this;
    }
    // 初始化弹出我的商城
    public ShowCommentDialog showMyDataShopStoreShop(){
        ImageView imageView = new ImageView(context);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        imageView.setLayoutParams(params);
        imageView.setImageResource(R.drawable.data_dialog_image8);
        ll_contentshowdatal.setGravity( Gravity.RIGHT| Gravity.TOP);
        ll_contentshowdatal.setPadding(DensityUtil.dip2px(context,0),DensityUtil.dip2px(context,30),DensityUtil.dip2px(context,5),0);
        ll_contentshowdatal.addView(imageView);
        return this;
    }

    /**
     * 弹出红包dialog
     * @return
     */
    public  ShowCommentDialog createRedPackageDialog(View.OnClickListener grapOnClickListener){
        View view = View.inflate(context, R.layout.layout_red_packet_dialog, null);
        ll_contentshowdatal.addView(view);
        ll_contentshowdatal.setGravity(Gravity.CENTER|Gravity.RIGHT);
        TextView tv_gethealthcoin = (TextView) view.findViewById(R.id.iv_open);
        ImageView iv_close = (ImageView) view.findViewById(R.id.iv_close);
        tv_gethealthcoin.setOnClickListener( grapOnClickListener);
        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               if(isShowing()){
                   dismiss();
               }
            }
        });
        return this;
    }


    public ShowCommentDialog dismissDialog(){
        if(isShowing()){
            dismiss();
        }
        return this;
    }
    public ShowCommentDialog showDialog(){
        if(!isShowing()){
            show();
        }
        return this;
    }

    /**
     * 点击图片进行的回掉事件
     * @param onClickListener
     * @return
     */
    public ShowCommentDialog setMyClickListener(View.OnClickListener onClickListener){
        ll_contentshowdatal.setOnClickListener(onClickListener);
        return this;
    }
}
